package com.ynrcc.util;

import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.OracleDialect;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.ynrcc.model.Attachment;
import com.ynrcc.model.Doc;
import com.ynrcc.model.EovaUser;
import com.ynrcc.model.Receive;
import com.ynrcc.model.Send;
import com.ynrcc.model.SysOrgElement;
import com.ynrcc.model.SysOrgPerson;

public class ConnDB {
	public static boolean connDB() {
		Prop p = PropKit.use("default/jdbc.config");
		C3p0Plugin c3p0Plugin = new C3p0Plugin(p.get("main_url"), p.get("main_user"), p.get("main_pwd"));
		if (!c3p0Plugin.start()) {
			return false;
		}
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin.getDataSource());
		arp.setDialect(new OracleDialect());
		arp.addMapping("doc", Doc.class);
		arp.addMapping("receive", Receive.class);
		arp.addMapping("send", Send.class);
		arp.addMapping("attachment", Attachment.class);
		arp.addMapping("eova_user", EovaUser.class);
		
		//arp.addMapping("sys_org_element", SysOrgElement.class);
		//arp.addMapping("sys_org_person", SysOrgPerson.class);
		
		// 与web环境唯一的不同是要手动调用一次相关插件的start()方法
		if (!arp.start()) {
			return false;
		}
		return true;
	}
}
